home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / Development / Example_Code_v37 / Libraries / DOS / pattern.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-17  |  2.1 KB  |  103 lines

  1. #include <exec/types.h>
  2. #include <exec/execbase.h>
  3. #include <dos/dos.h>
  4. #include <dos/dosextens.h>
  5. #include <dos/dosasl.h>
  6. #include <clib/dos_protos.h>
  7.  
  8. #include <string.h>
  9. #include <stdio.h>
  10.  
  11. struct AnchorPath MyAp;
  12.  
  13. #define SAME 0
  14.  
  15. int
  16. main(argc,argv)
  17.     int    argc;
  18.     char    *argv[];
  19. {
  20.     LONG    retval = RETURN_ERROR;
  21.     LONG    all = FALSE;
  22.     char    dirname[256];
  23.  
  24.     if (argc < 2 || argc > 3)
  25.     {
  26. usage:        printf("Usage: %s <pattern> [all]\n",argv[0]);
  27.         return retval;
  28.     }
  29.  
  30.     if (argc == 3)
  31.     {
  32.         if (stricmp(argv[2],"all") == SAME)
  33.             all = TRUE;
  34.         else
  35.             goto usage;
  36.     }
  37.  
  38.     printf("Searching directory tree for pattern %s\n",argv[1]);
  39.  
  40.     /* Initialize the AnchorPath structure    */
  41.     MyAp.ap_BreakBits = SIGBREAKF_CTRL_C; /* Break on these bits    */
  42.  
  43.     for (retval = MatchFirst(argv[1],&MyAp);
  44.          retval == 0;
  45.          retval = MatchNext(&MyAp))
  46.     {
  47.         if (MyAp.ap_Flags & APF_DirChanged)
  48.         {
  49.             printf("Changed directories...\n");
  50.         }
  51.  
  52.         if (NameFromLock(MyAp.ap_Current->an_Lock,dirname,
  53.                  sizeof(dirname)) == FALSE)
  54.         {
  55.             PrintFault(IoErr(),"Error on NameFromLock");
  56.             break;
  57.         }
  58.         if (AddPart(dirname,&(MyAp.ap_Info.fib_FileName[0]),
  59.                 sizeof(dirname)) == FALSE)
  60.         {
  61.             PrintFault(IoErr(),"Error on AddPart");
  62.             break;
  63.         }
  64.  
  65.     /* This code section deals with ALL and directory ascent/descent */
  66.         if (MyAp.ap_Info.fib_DirEntryType > 0)
  67.         {
  68.             if (MyAp.ap_Flags & APF_DIDDIR)
  69.             {
  70.             printf("Ascending from directory %s\n",dirname);
  71.  
  72.             } else if (all) {
  73.  
  74.             printf("Entering directory %s\n",dirname);
  75.  
  76.             /* make it enter the directory */
  77.             MyAp.ap_Flags |= APF_DODIR;
  78.  
  79.             } else {
  80.             printf("The next dir is  ... %s\n",dirname);
  81.             }
  82.  
  83.             /* clear the completed directory flag */
  84.             MyAp.ap_Flags &= ~APF_DIDDIR;
  85.  
  86.         } else {
  87.             /* Here is code for handling each particular file */
  88.             printf("The next file is ... %s\n",dirname);
  89.         }
  90.     }
  91.  
  92.     /* This absolutely, positively must be called, all of the time. */
  93.     MatchEnd(&MyAp);
  94.  
  95.     /* Check for error, if so, print error message */
  96.     if (retval != ERROR_NO_MORE_ENTRIES)
  97.     {
  98.     printf("%s failed because Error code %ld\n",argv[0],retval);
  99.     PrintFault(retval,NULL);
  100.     }
  101. }
  102.  
  103.